package com.cbgolf.oa.util;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.cbgolf.oa.app.App;


/**
 * Created by lq on 2017/7/17.
 */

public class ScreenUtil {

    public static void LightOff(Activity ac) {
        WindowManager.LayoutParams params = ac.getWindow().getAttributes();
        params.alpha = 0.7f;
        ac.getWindow().setAttributes(params);
    }

    public static void LightOn(Activity ac) {
        WindowManager.LayoutParams params = ac.getWindow().getAttributes();
        params.alpha = 1f;
        ac.getWindow().setAttributes(params);
    }

    public static DisplayMetrics getDisplayMetrics() {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) App.getContext().getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        return dm;
    }

    public static int getWidth() {
        return getDisplayMetrics().widthPixels;
    }

    public static int getHeight() {
        return getDisplayMetrics().heightPixels;
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明
     */
    public static void setBackgroundAlpha(Activity context, float bgAlpha) {
        WindowManager.LayoutParams lp = context.getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        context.getWindow().setAttributes(lp);
    }

}
